package com.sharkburner.aeris.service.article;

import java.util.List;
import java.util.TimerTask;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.sharkburner.aeris.bean.article.ArticleBean;
import com.sharkburner.aeris.dao.entity.Site;
import com.sharkburner.aeris.service.source.SourceService;

@Component
public class ArticleScanner extends TimerTask {

	@Autowired
	protected ArticleService articleService;

	@Autowired
	protected SourceService sourceService;

	@Autowired
	protected BeanFactory beanFactory;

	@Autowired
	protected ArticleReader articleReader;

	@Override
	public void run() {
		List<Site> sites = sourceService.findSources();

		for (Site site : sites) {
			String link = site.getLink();
			if (link != null) {
				List<ArticleBean> articleBeans = articleReader
						.getArticles(link);
				articleService.save(site, articleBeans);
			}
		}
	}
}
